-- Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
--
-- this file licensed under the Mulan PSL v2.
-- You can use this software according to the terms and conditions of the Mulan PSL v2.
-- You may obtain a copy of Mulan PSL v2 at: http://license.coscl.org.cn/MulanPSL2
--
-- THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
-- PURPOSE.
-- See the Mulan PSL v2 for more details.
--
-- Author: auto generate
-- Create: 2025-8-19
-- Description: DO NOT EDIT; Code generated by "service.lua.mako"
local ipmi = require 'ipmi'
local mdb = require 'mc.mdb'
local class = require 'mc.class'
local app_base = require 'mc.service_app_base'
local object_manage = require 'mc.mdb.object_manage'

local CommunityTypes = require 'my_app.json_types.Community'
local PropertiesTypes = require 'my_app.json_types.Properties'
local ReadingTypes = require 'my_app.json_types.Reading'

local MyMDSModel = mdb.register_object('/bmc/demo/MyMDSModel/:id', {
    {name = 'bmc.demo.OpenUBMC.Community', interface = CommunityTypes.interface},
    {name = 'bmc.kepler.Object.Properties', interface = PropertiesTypes.interface}
})

function MyMDSModel:ctor(id)
    self.path = '/bmc/demo/MyMDSModel/' .. id
end

local MyCSRModel = mdb.register_object('/bmc/demo/MyCSRModel/:id', {
    {name = 'bmc.demo.OpenUBMC.Reading', interface = ReadingTypes.interface},
    {name = 'bmc.kepler.Object.Properties', interface = PropertiesTypes.interface}
})

function MyCSRModel:ctor(id)
    self.path = '/bmc/demo/MyCSRModel/' .. id
end

local model = require 'class.model'

local my_app_service = class(app_base.Service)

my_app_service.package = 'my_app'

function my_app_service:CreateMyMDSModel(id, prop_setting_cb)
    local path = '/bmc/demo/MyMDSModel/' .. id
    return object_manage.create_object('MyMDSModel', path, path, prop_setting_cb)
end

function my_app_service:CreateMyCSRModel(id, prop_setting_cb)
    local path = '/bmc/demo/MyCSRModel/' .. id
    return object_manage.create_object('MyCSRModel', path, path, prop_setting_cb)
end

function my_app_service:ImplMyMDSModelCommunityGetRepoURL(cb)
    model.ImplMyMDSModelCommunityGetRepoURL(cb)
end

function my_app_service:get_bus()
    return self.bus
end

function my_app_service:register_ipmi_cmd(ipmi_cmd, cb)
    self.ipmi_cmds[ipmi_cmd.name] = ipmi.register_ipmi_cmd(self.bus, self.service_name, ipmi_cmd,
        cb or self[ipmi_cmd.name])
end

function my_app_service:unregister_ipmi_cmd(ipmi_cmd)
    local cmd_obj = self.ipmi_cmds[ipmi_cmd.name]
    if not cmd_obj then
        return
    end

    cmd_obj:unregister()
    self.ipmi_cmds[ipmi_cmd.name] = nil
end

function my_app_service:ctor()
    self.ipmi_cmds = {}
    self.signal_slots = {}
    self.name = self.name or my_app_service.package

    self.bus:request_name(app_base.Service.get_service_name(self.name))
    model.init(self.bus)
    my_app_service.bus = self.bus
end

function my_app_service:pre_init()
    my_app_service.super.pre_init(self)
end

function my_app_service:init()
    my_app_service.super.init(self)
end

return my_app_service
